<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" type="text/css" href="format.css" />
	<title>Facelets Template</title>
</h:head>
<h:body>
	<ui:composition template="/template.xhtml">
		<ui:define name="ui_right">
			<h:form prependId="false" id="form">
				<p:growl id="messages" />
				<p:panel>
					<p:dataTable id="ogloszenia" paginator="true" rows="5"
						rowsPerPageTemplate="5, 10, 15"
						value="#{displayAdvertisementsBean.getAdvertisementsFromSearch()}"
						var="o" emptyMessage="Nie znaleziono żadnych ogłoszeń">

						<p:column headerText="Ważne od" style="width:100px">  
				            #{o.startDate}
				        </p:column>
						<p:column headerText="Tytuł" style="width:100px">  
				            #{o.title}
				        </p:column>

						<p:column headerText="Treść" style="width:300px">  
				            #{o.content}
				        </p:column>

						<p:column headerText="Kategoria" style="width:100px">  
				             #{o.category.name}
				        </p:column>

						<p:column headerText="Typ" style="width:100px">  
				             #{o.type.name}
				        </p:column>
						<p:column headerText="Edytuj">
							<p:commandButton value="Edytuj" ajax="true"
								style="margin-left:5px;"
								oncomplete="editingAdvertisementDialog.show()"
								update=":form:dialog">
								<f:setPropertyActionListener
									target="#{displayAdvertisementsBean.selectedAdvertisementEdit}"
									value="#{o}"></f:setPropertyActionListener>
							</p:commandButton>
						</p:column>

						<p:column headerText="Usuń">
							<p:commandButton value="Usuń" ajax="true"
								style="margin-left:5px;"
								oncomplete="deletingAdvertisementDialog.show()"
								update=":form:dialog4">
								<f:setPropertyActionListener
									target="#{displayAdvertisementsBean.selectedAdvertisementDelete}"
									value="#{o}"></f:setPropertyActionListener>
							</p:commandButton>
						</p:column>


						<p:column style="width:40px">
							<h:panelGrid columns="3" styleClass="actions" cellpadding="2">

								<p:commandButton id="selectButton" title="Przejdź" ajax="false"
									icon="ui-icon-search" action="result">
									<f:setPropertyActionListener
										target="#{displayAdvertisementsBean.selectedAdvertisement}"
										value="#{o}" />
								</p:commandButton>

							</h:panelGrid>
						</p:column>

					</p:dataTable>
				</p:panel>
				<p:dialog id="dialog" header="Edytuj" dynamic="false"
					widgetVar="editingAdvertisementDialog" resizable="true" width="850"
					showEffect="clip" hideEffect="fold">
					<p:messages for="adding" id="msgs2" />
					<p:panelGrid columns="3" style="width:690px;">

						<f:facet name="header">
									Edytuj ogloszenie
								</f:facet>

						<h:outputText value="Tytul " />
						<h:inputText
							value="#{displayAdvertisementsBean.selectedAdvertisementEdit.title}" />
						<h:outputText value="" />

						<h:outputText value="Content" />
						<h:inputTextarea
							value="#{displayAdvertisementsBean.selectedAdvertisementEdit.content}" />
						<h:outputText value="" />

						<h:outputText value="Ważne od" />
						<p:calendar
							value="#{displayAdvertisementsBean.selectedAdvertisementEdit.startDate}" />
						<h:outputText value="" />

						<h:outputText value="Ważne do" />
						<p:calendar
							value="#{displayAdvertisementsBean.selectedAdvertisementEdit.expireDate}" />
						<h:outputText value="" />

						<h:inputHidden
							value="#{displayAdvertisementsBean.selectedAdvertisementEdit.advertisement_id}" />

						<p:commandButton value="Anuluj"
							oncomplete="editingAdvertisementDialog.hide();" />
						<p:commandButton value="Edytuj"
							action="#{displayAdvertisementsBean.tryEdit}" ajax="true"
							update="msgs2, :form:ogloszenia" />

					</p:panelGrid>
				</p:dialog>

				<p:dialog id="dialog4" header="Usuń ogloszenie"
					widgetVar="deletingAdvertisementDialog" resizable="true"
					width="450" showEffect="clip" hideEffect="fold">
					<p:messages id="msgs4" for="deleting" />
					<p:panelGrid columns="1">
						<h:outputText value="Tytuł " />
						<h:inputText
							value="#{displayAdvertisementsBean.selectedAdvertisementDelete.title}" />
						<h:outputText value="" />
						<h:inputHidden
							value="#{displayAdvertisementsBean.selectedAdvertisementDelete.advertisement_id}" />
						<h:outputText
							value="Operacja usunie ogłoszenie z bazy danych. Czy na pewno chcesz kontynuować?" />
						<p:panelGrid columns="2">
							<p:commandButton value="Anuluj"
								oncomplete="deletingAdvertisementDialog.hide();" />
							<p:commandButton value="Usuń" ajax="true"
								style="margin-left:5px;"
								action="#{displayAdvertisementsBean.tryDelete}"
								update=":form:ogloszenia, msgs4">
							</p:commandButton>
						</p:panelGrid>
					</p:panelGrid>
				</p:dialog>

			</h:form>
		</ui:define>
	</ui:composition>
</h:body>
</html>
